package com.rong.raft.rpc;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import com.rong.raft.LeaderSelector;
import com.rong.raft.rpc.protocol.HeartbeatRequest;
import com.rong.raft.rpc.protocol.VoteRequest;
import com.rong.raft.rpc.protocol.VoteResponse;

public class RpcServiceImpl extends UnicastRemoteObject implements IRpcService {

	private static final long serialVersionUID = 1L;

	private LeaderSelector leaderSelector;

	public RpcServiceImpl() throws RemoteException {
		super();
	}

	public RpcServiceImpl(LeaderSelector leaderSelector) throws RemoteException {
		this();
		this.leaderSelector = leaderSelector;
	}

	public VoteResponse sendVote(VoteRequest voteRequest) throws RemoteException {
		return leaderSelector.handleVote(voteRequest);
	}

	public void sendHeartBeat(HeartbeatRequest heartbeatRequest) throws RemoteException {
		leaderSelector.handleHeartBeart(heartbeatRequest);
	}

}
